package com.wyl.mapper;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.wyl.model.Simple;

@Mapper
public interface SimpleMapper {

	@Select("select * from `news_simple` where `channelname`=#{type} and `has_content` = true order by `time` desc limit #{offset},#{limit}")
	public List<Simple> selectByOffsetAndType(@Param("type")String type,@Param("offset")Integer offset, @Param("limit")Integer limit) ;
	
	@Select("select * from `news_simple` where `docurl`=#{docurl}")
	public Simple selectByDocurl(@Param("docurl")String url);
	
	@Select("select * from `news_simple` where `has_content` = false")
	public List<Simple> selectNoContent();
	
	@Insert("insert into `news_simple`(`title`,`docurl`,`time`,`channelname`,`imgurl`,`has_content`)values"
			+ "(#{title},#{docurl},#{time},#{channelname},#{imgurl},#{hasContent})")
	public void save(@Param("title")String title,
			@Param("docurl")String docurl,
			@Param("time")Date time,
			@Param("channelname")String channelname,
			@Param("imgurl")String imgurl,
			@Param("hasContent")Boolean hasContent);
	
	@Delete("truncate table `news_simple`")
	public void clear();

	@Update("update `news_simple` set `has_content` = #{hasContent} where `id`=#{id}")
	public void updateContentState(@Param("id")Integer id,@Param("hasContent")boolean hasContent);

	@Select("select * from `news_simple`")
	public List<Simple> selectAll();
}
